package com.reza.simpd.util
{
	import com.reza.simpd.components.notifications.Notification;
	
	import flash.display.Bitmap;
	import flash.net.SharedObject;
	import flash.utils.ByteArray;
	
	import mx.formatters.DateFormatter;
	import mx.utils.Base64Decoder;
	import mx.utils.Base64Encoder;
	import flash.utils.describeType;

	public class Helper{
		private var _sharedObjectKegiatan:SharedObject;
		private var _sharedObjectSuratTugas:SharedObject;
		private var _sharedObjectSPPD:SharedObject;
		private var _sharedObjectKwitansi:SharedObject;
		private var _sharedObjectNominatifPerjalananDinas:SharedObject;
		private var _sharedObjectNotaDinas:SharedObject;
		
		public function Helper()
		{
			_sharedObjectKegiatan = SharedObject.getLocal(System.SHARED_OBJECT_KEGIATAN);
			_sharedObjectSuratTugas = SharedObject.getLocal(System.SHARED_OBJECT_SURAT_TUGAS);
			_sharedObjectSPPD = SharedObject.getLocal(System.SHARED_OBJECT_SPPD);
			_sharedObjectKwitansi = SharedObject.getLocal(System.SHARED_OBJECT_KWITANSI);
			_sharedObjectNominatifPerjalananDinas = SharedObject.getLocal(System.SHARED_OBJECT_NOMINATIF_PERJALANAN_DINAS);
			_sharedObjectNotaDinas = SharedObject.getLocal(System.SHARED_OBJECT_NOTA_DINAS);
		}
	
		public function get sharedObjectNotaDinas():SharedObject
		{
			return _sharedObjectNotaDinas;
		}

		public function set sharedObjectNotaDinas(value:SharedObject):void
		{
			_sharedObjectNotaDinas = value;
		}

		public function get sharedObjectKwitansi():SharedObject
		{
			return _sharedObjectKwitansi;
		}

		public function set sharedObjectKwitansi(value:SharedObject):void
		{
			_sharedObjectKwitansi = value;
		}

		public function get sharedObjectSPPD():SharedObject
		{
			return _sharedObjectSPPD;
		}

		public function set sharedObjectSPPD(value:SharedObject):void
		{
			_sharedObjectSPPD = value;
		}

		public function get sharedObjectNominatifPerjalananDinas():SharedObject
		{
			return _sharedObjectNominatifPerjalananDinas;
		}

		public function set sharedObjectNominatifPerjalananDinas(value:SharedObject):void
		{
			_sharedObjectNominatifPerjalananDinas = value;
		}

		public function get sharedObjectSuratTugas():SharedObject
		{
			return _sharedObjectSuratTugas;
		}

		public function set sharedObjectSuratTugas(value:SharedObject):void
		{
			_sharedObjectSuratTugas = value;
		}

		public function get sharedObjectKegiatan():SharedObject
		{
			return _sharedObjectKegiatan;
		}

		public function set sharedObjectKegiatan(value:SharedObject):void
		{
			_sharedObjectKegiatan = value;
		}

		public static function showInformation(message:String, position:String = ""):void{
			Notification.show(message, "Informasi", 3000, position, Notification.NOTIFICATION_TYPE_INFORMATION, true);
		}
		
		public static function showWarning(message:String, position:String = ""):void{
			Notification.show(message, "Peringatan", 3000, position, Notification.NOTIFICATION_TYPE_WARNING, true);
		}
		
		public static function showError(message:String, position:String = ""):void{
			Notification.show(message, "Kesalahan", 3000, position, Notification.NOTIFICATION_TYPE_ERROR, true);
		}
		
		public static function currentDateTimeString(showTime:Boolean = false):String
		{               
			var CurrentDateTime:Date = new Date();
			var CurrentDF:DateFormatter = new DateFormatter();
			if(showTime == false)
			{
				CurrentDF.formatString = "YYYY-MM-DD";
			}
			else
			{
				CurrentDF.formatString = "YYYY-MM-DD HH:NN:SS";
			}
			var DateTimeString:String = CurrentDF.format(CurrentDateTime);
			return DateTimeString;
		}
		
		public static function formatToSQLDate(date:Date):String{
			var sqlDF:DateFormatter = new DateFormatter();
			sqlDF.formatString = "YYYY-MM-DD";
			return sqlDF.format(date);
		}
		
		/**
		 * @Deprecated
		 * 
		 * # Diganti DateUtils pada library FlexOOPUtilities.swc
		 * 
		 */ 
		/*public static function differenceBetweenDates(date1:Date, date2:Date):Number{
			var MS_PER_DAY:uint = 1000 * 60 * 60 * 24;
			var tempDate:Date = new Date(date2.time - date1.time);
			var difference:Number = 
				Math.abs(Math.round((tempDate.time / MS_PER_DAY)));
			return difference;
		}*/
		
		public static function stringParser(separator:String, textToParse:String):Array
		{
			return textToParse.split(separator);
		}
	}
}